home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / dos / fs / rxbackup.1 < prev    next >
Encoding:
Internet Message Format  |  1989-05-18  |  8.6 KB

  1. Path: wuarchive!wugate!uunet!cs.utexas.edu!sun-barr!sun!swap!page
  2. From: page%swap@Sun.COM (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i139:  backup.rexx - a backup script in arexx
  5. Message-ID: <105548@sun.Eng.Sun.COM>
  6. Date: 17 May 89 15:08:25 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 284
  9. Approved: page@sun.com
  10.  
  11. Submitted-by: bmacintyre@watcgl.waterloo.edu (Blair MacIntyre)
  12. Posting-number: Volume 89, Issue 139
  13. Archive-name: dos/fs/rxbackup.1
  14.  
  15. backup.rexx behaves much like the Unix backup program, creating a
  16. directory tree with a directory for each file and saving files by the
  17. date they were changed.
  18.  
  19. The reason I am posting this is to allow others to have yet-another
  20. sample Arexx program.  Besides, I think it's useful!!
  21.  
  22. [unix has a 'backup' program?  ..bob]
  23.  
  24. # This is a shell archive.
  25. # Remove anything above and including the cut line.
  26. # Then run the rest of the file through 'sh'.
  27. # Unpacked files will be owned by you and have default permissions.
  28. #----cut here-----cut here-----cut here-----cut here----#
  29. #!/bin/sh
  30. # shar: SHell ARchive
  31. # Run the following text through 'sh' to create:
  32. #    Readme
  33. #    backup.rexx
  34. # This is archive 1 of a 1-part kit.
  35. # This archive created: Wed May 17 20:01:54 1989
  36. echo "extracting Readme"
  37. sed 's/^X//' << \SHAR_EOF > Readme
  38. XOk, so I finally got around to using ARexx, after watching the manual
  39. Xcollect dust for 4 months.  As I posted recently, I would have really
  40. Xliked more examples ... it would have been easier.  But it was 
  41. Xsurprisingly easy.
  42. X
  43. XSo, my first effort is a script called backup.rexx which is based on
  44. Xarchie.rexx ( which I think I got off of comp.sources.amiga some
  45. Xtime ago. )
  46. X
  47. XIt behaves much like the Unix backup program, creating a directory
  48. Xtree with a directory for each file and saving files by the date
  49. Xthey were changed.
  50. X
  51. Xie. backing up /d1/d2/file with a file stamp of 01 May 11:15 would give
  52. X        /d1/d2/file/01-May-11-15 in the backup directory
  53. X
  54. XThe source and destination directories are specified at execution time.
  55. X
  56. XThe reason I am posting this is to allow others to have yet-another
  57. Xsample Arexx program.  Besides, I think it's useful!!
  58. X
  59. XOne thing to note is that is corrects a problem in Archie.rexx, which
  60. Xwouldn't work on files or directories with embedded spaces in the name.
  61. XRead the comments to see how.  
  62. X
  63. XAnother interesting point was that, for safety, I had to force quotation
  64. Xof the "makedir" and "copy" parameters, because a file such as "blat5.1+" 
  65. Xneeds to be quoted, for example.  I discovered that the hard way!
  66. X
  67. XNOTE:  you need some form of ls (I'm using the Manx one) in your C:
  68. Xdir for this to work!!!
  69. X
  70. X=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-///-=
  71. X= Blair MacIntyre, bmacintyre@watcgl.{waterloo.edu, UWaterloo.ca}     \\\///  =
  72. X=   now appearing at the Computer Graphics Lab, U of Waterloo!         \XX/   =
  73. X= "Don't be mean ... remember, no matter where you go, there you are." BBanzai=
  74. X
  75. X
  76. SHAR_EOF
  77. echo "extracting backup.rexx"
  78. sed 's/^X//' << \SHAR_EOF > backup.rexx
  79. X/*
  80. X *   Backup.rexx -- by Blair MacIntyre
  81. X *     a temporary backup utility based on
  82. X *       Archie.rexx -- a backup utility by <CB> aka Christian Balzer
  83. X *              which was based on du.rexx by Larry Phillips.
  84. X *
  85. X * Usage: [rx] backup SOURCE DESTINATION [-options]
  86. X *
  87. X * SOURCE and DESTINATION are valid AmigaDOS path's WITHOUT trailing
  88. X * slashes '/'.
  89. X * Valid options are: Currently none...
  90. X *
  91. X * Backup will copy all files that don't have the archive bit set
  92. X * from SOURCE and it's subdirectories to DESTINATION, with the modification
  93. X * that each file will now be a directory and will have files for each time
  94. X * copied with the filename being the date.
  95. X *
  96. X * If these directories don't exist at DESTINATION, backup will try to create
  97. X * them on the fly and thus preserving the original structure at SOURCE.
  98. X * After the file has been copied, it's archive bit will be set.
  99. X *
  100. X * Note: The files will be copied with 'CLONE' flag of the COPY command
  101. X * set. This of course only works with the 1.3 version of COPY.
  102. X *
  103. X * Unlike Archie, filenames or directories containing blanks
  104. X * (like "My Dir:My File"), ARE supported!
  105. X *
  106. X * BIG NOTE:  you need "ls" in your c: directory.  I have tried this
  107. X *            with the manx ls, so I don't know about the PD one.
  108. X *
  109. X */
  110. X
  111. X/* This is Public Domain, read the source and learn - I did!!! */
  112. X
  113. Xsay 'Backup 2.4 (Based on Archie 1.6) (3-May-89)'
  114. X
  115. X/* open the Rexx support library */
  116. X
  117. Xif ~show('L',"rexxsupport.library") then
  118. Xdo
  119. X    if addlib('rexxsupport.library',0,-30,0) then
  120. X    say 'added rexxsupport.library'
  121. X    else
  122. X    do
  123. X    say 'support library not available'
  124. X    exit 10
  125. X    end
  126. Xend
  127. X
  128. Xaddress command
  129. Xcall pragma 'priority',-1
  130. X
  131. Xarg rein
  132. X
  133. X/* The parser */
  134. Xcopt = 'clone'
  135. X
  136. Xif words(rein) < 2 then
  137. Xdo
  138. X    say 'Backup: give me a SOURCE *AND* a DESTINATION path'
  139. X    exit 10
  140. Xend
  141. X
  142. Xroot = subword(rein,1,1)
  143. Xdest = subword(rein,2,1)
  144. X
  145. Xif ~ exists(root) then
  146. Xdo
  147. X    say 'Source not found'
  148. X    say 'Exiting... Check your parameters'
  149. X    exit 10
  150. Xend
  151. X
  152. X/* enclose file parms for makedir ( and eventually, copy ) in "quotes" to
  153. X   handle spaces */
  154. X
  155. Xif ~ exists(dest) then
  156. Xdo
  157. X    say 'Destination not found'
  158. X    newdest = """" || dest || """"
  159. X    say 'I''ll try to create it for you...'newdest
  160. X    'makedir ' newdest
  161. X    if ~ exists(dest) then
  162. X    do
  163. X    say 'Exiting... Check your parameters'
  164. X    exit 15
  165. X    end
  166. X    say 'Created 'dest
  167. Xend
  168. X
  169. Xif right(root,1) ~= ':' then
  170. X    root = root || '/'
  171. Xif root = '/' then
  172. X    root = ''
  173. X
  174. Xif right(dest,1) ~= ':' then
  175. X    dest = dest || '/'
  176. Xif dest = '/' then
  177. X    dest = ''
  178. X
  179. Xrlen = length(root)
  180. X
  181. Xbytes = 0
  182. Xblocks = 0
  183. Xfiles = 0
  184. Xdircount = 1
  185. X
  186. Xsay 'Backup is doing it''s job on 'root
  187. Xcall dolist root , 1
  188. X
  189. Xsay
  190. Xsay 'Backed Up:' bytes 'bytes,' blocks 'blocks, ',
  191. X     files 'files in a total 'dircount' directories.'
  192. Xexit 0
  193. X
  194. X/* The real thing
  195. X *
  196. X * x is the dir we are working on
  197. X * depth is the recursion level, so we can have a unique pipe!
  198. X */
  199. X
  200. Xdolist: procedure expose bytes blocks files dest rlen dircount copt
  201. Xparse arg x, depth
  202. X
  203. Xsay 'working on directory' x
  204. X
  205. X/* I'm not using showdir() for the file list because I want the time
  206. X   stamps as well - can you say KLUDGE boys and girls?!?  Good, I knew you
  207. X   could! */
  208. X
  209. Xpipefile = "pipe:backup_ls_" || depth
  210. Xthedate = 'file' || depth
  211. Xcall open thedate, pipefile, 'Read'
  212. X'ls' ">"pipefile "-l" x
  213. X
  214. X/* the other reason for not using showdir() is that the filenames with spaces
  215. X   get split up and we can't tell which they are ... */
  216. X
  217. Xdo forever
  218. X
  219. X    /* datestr contains the "ls -l" line for the current file */
  220. X    datestr = readln( thedate )
  221. X
  222. X    /* if the number of words is less than 6, this is not a file line,
  223. X       which means it is the "No files found" line.  However, I'm not making
  224. X       it dependent on that exact string */
  225. X    if words( datestr ) < 6 then
  226. X    leave
  227. X
  228. X    /* apparantly the Manx version of ls doesn't print the summary line if
  229. X       a directory only has one subfile ... pftt! */
  230. X    if eof( thedate ) then
  231. X       leave
  232. X
  233. X    /* the last line of an "ls -l" starts with a number */
  234. X    if datatype(word(datestr,1), 'Numeric') then
  235. X    leave
  236. X
  237. X    /* I used to grad the 6th word as the file name, but that went TU on names
  238. X       with embedded spaces.  Grab *ALL* after the 5th ... */
  239. X    temp = x || subword(datestr, 6)
  240. X    flen = length(subword(datestr, 6))
  241. X    type = statef(temp)
  242. X
  243. X    /* create a subdir for all dirs AND files! */
  244. X    subdir = dest || right(temp,(length(temp) - rlen))
  245. X    if ~ exists(subdir) then
  246. X    do
  247. X    say ' *** Creating directory' subdir
  248. X    newsubdir = """" || subdir || """"
  249. X    'makedir' newsubdir
  250. X    if ~ exists(subdir) then
  251. X    do
  252. X        say 'Oop Ack Pftt ... sorry ... Exiting'
  253. X        exit 20
  254. X    end
  255. X    end
  256. X
  257. X    /* recursively do directories */
  258. X
  259. X    if word(type,1) = 'DIR' then
  260. X    do
  261. X    call dolist temp || '/', depth + 1
  262. X    dircount = dircount + 1
  263. X    end
  264. X
  265. X    /* files get dated files made of them! */
  266. X    if word(type,1) = 'FILE' then
  267. X    do
  268. X    if substr(word(type,4),4,1) = '-' then
  269. X    do
  270. X
  271. X        datefile = word(datestr,3) || '-' || word(datestr,4) || '-' || overlay('-',word(datestr,5),'3')
  272. X        target = dest || right(temp,(length(temp) - rlen)) || '/' || datefile
  273. X
  274. X        if ~ exists(target) then
  275. X        do
  276. X        newsrc = """" || temp || """"
  277. X        newtgt = """" || target || """"
  278. X        'copy ' newsrc newtgt copt
  279. X        files = files + 1
  280. X        bytes = bytes + word(type,2)
  281. X        blocks = blocks + word(type,3) + 1
  282. X        say 'Backed up file 'temp' as 'datefile
  283. X        end
  284. X    end
  285. X    end
  286. Xend
  287. X
  288. Xcall close thedate
  289. X
  290. Xreturn
  291. SHAR_EOF
  292. echo "End of archive 1 (of 1)"
  293. # if you want to concatenate archives, remove anything after this line
  294. exit
  295.